package com.lqq.controller.restfull;

import com.lqq.producer.Producer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.rocketmq.client.producer.SendResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author lqq
 * @date 2019/1/6
 */
@RestController
@Api(description = "index")
public class IndexController {


    @RequestMapping({"", "/" , "/index"})
    @ApiOperation(value = "index",httpMethod = "GET")
    public String index() throws UnknownHostException {
        InetAddress address = InetAddress.getLocalHost();
        return  "indexMethod: 当前主机ip地址信息：" + address.getHostAddress();
    }

    @RequestMapping({"/produce"})
    @ApiOperation(value = "产生消息",httpMethod = "GET")
    public String produce(@RequestParam String msg) throws UnknownHostException {
        //TODO 发送消息
        Producer producer = Producer.getInstance();
        SendResult sendResult = producer.send(msg);
        return  "消息'" + msg + "'已经发送" + sendResult;
    }
}
